<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8" />
		<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
		<meta name="HandheldFriendly" content="true" />
		<meta name="MobileOptimized" content="320" />
		<link rel="stylesheet" href="css/mui.min.css" type="text/css" charset="utf-8" />
		<link rel="stylesheet" href="css/style.css" type="text/css" charset="utf-8" />
		<style type="text/css"> #bcid { width: 100%; position: absolute; top: 0.88rem; bottom: 0px; left: 0px; text-align: center; }  .tip { color: #FFFFFF; font-weight: bold; text-shadow: 0px -1px #103E5C; text-align: center; line-height: 100vh; } </style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav mui-header">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">扫码</h1>
		</header>
		<div class="mui-content">
			<div id="bcid">
				<p class="tip" style="color:#666;text-shadow: none;">载入中...</p>
			</div>
		</div> 
		<script src="js/resize.js"></script>
		<script src="js/mui.min.js"></script>

		<script type="text/javascript">
			var flag=1;
			var ws = null,
				wo = null;
			var scan = null,
				domready = false;
			var dialogWindow;
			var count=0;
			// H5 plus事件处理
			function plusReady() {
				if(ws || !window.plus || !domready) {
					return;
				}		
				// 获取窗口对象
				ws = plus.webview.currentWebview();
				var scan_result_view = plus.webview.create('scan-result.html');
				wo = scan_result_view;
				// 开始扫描
				ws.addEventListener('show', function() {
					var self = plus.webview.currentWebview();
					flag = self.flag; /*1表示入库，2表示出库*/
					scan = new plus.barcode.Barcode('bcid');
					scan.onmarked = onmarked;
					scan.start();
				});

				// 显示页面并关闭等待框
				ws.show("pop-in");
				plus.nativeUI.closeWaiting();
			}

			if(window.plus) {
				plusReady();
			} else {
				document.addEventListener("plusready", plusReady, false);
			}
			// 监听DOMContentLoaded事件
			document.addEventListener("DOMContentLoaded", function() {
				domready = true;
				plusReady();
			}, false);
			// 二维码扫描成功
			function onmarked(type, result, file) {
				switch(type) {
					case plus.barcode.QR:
						type = "QR";
						break;
					case plus.barcode.EAN13:
						type = "EAN13";
						break;
					case plus.barcode.EAN8:
						type = "EAN8";
						break;
					default:
						type = "其它";
						break;
				}
				result = result.replace(/\n/g, '');
				wo.evalJS("scaned('" + type + "','" + result + "','" + flag + "');");
			}
			/*mui.back=function(){
				dialogWindow=plus.webview.create('dialog.html','scandialog',{background:'transparent',zindex:'100',top:'40%'}); //创建弹窗
				dialogWindow=plus.webview.getWebviewById('scandialog');
				dialogWindow.show();	 
			}*/
			/*mui.back = function() {
				goback();
			};

			function goback(hide) {
				var w = window;
				if(w.plus) {
					ws || (ws = plus.webview.currentWebview());
					if(hide || ws.preate) {
						ws.hide('auto');
					} else {
						ws.close('auto');
					}
				} else if(history.length > 1) {
					history.back();
				} else {
					w.close();
				}
			}*/
		</script>
	</body>

</html>